#include "list.h"
#include <iostream>

using namespace std ;

myList::myList(list<double> l)
{
	int pos = 0 ;
	list<double>::iterator it ;
	for(it = l.begin() ; it != l.end() ; it ++)
	{
		this->li.push_back(*it) ;
	}
}

double* myList::getList()
{
	int i ;
	double *v = new double[this->li.size()] ;
	list<double>::iterator it ;
	for(it = this->li.begin(), i = 0 ; it != this->li.end() ; it ++, i ++)
	{
		v[i] = *it ;
	}
	return v ;
}

void myList::insert(double num, int pos)
{
	list<double>::iterator it = this->li.begin() ;
	if(pos > this->li.size())
	{
		cout << "Den mporeis na valeis se ayth thn thesh" << endl ;
		return ;
	}
	it += pos ;
	this->li.insert(it, num) ;
}

void increaseList(int startPos, double num)
{
	list<double>::iterator it ;
	for(it = this->li.begin() + startPos ; it != this->li.end() ; it ++)
	{
		*it += num ;
	}
}

void decreaseList(int startPos, double num)
{
	list<double>::iterator it ;
	for(it = this->li.begin() + startPos ; it != this->li.end() ; it ++)
	{
		*it -= num ;
	}
}


int insertRand(double num)
{
    srand(4) ;
    int pos = rand() % (this->li.size() - 1) ;
    list<double>::iterator it = this->li.begin() + pos ;
    this->li.insert(it, num) ;
    return pos ;
}

bool deleteFromList(double num)
{
    list<double>::iterator it ;
    bool found ;
    for(it = this->li.begin() ; it != this->li.end() ; it ++)
    {
        if(*it == num)
        {
            this->li.erase(it++) ;
            found = true ;
        }
    }
    return found ;
}


item deleteRand() {
	
	item itEM;
	
	srand(6);
	int position = rand() % (this->li.size() -1);
	list<double>::iterator it = this->li.begin() + pos;
	
	itEM.num=*it;
	itEM.pos=position;
	
	this->li.erase(it);
	
	return itEM;
}


void inverseList() {
	this->li.reverse();
}



























